package cn.zhoutingrui.pethome.system.login.controller;

import cn.zhoutingrui.pethome.base.constants.BaseConstants;
import cn.zhoutingrui.pethome.config.BussnisEptional;
import cn.zhoutingrui.pethome.system.emp.domain.EmployeeBo;
import cn.zhoutingrui.pethome.system.login.domain.WeChat;
import cn.zhoutingrui.pethome.system.logininfo.domain.Logininfo;
import cn.zhoutingrui.pethome.system.logininfo.service.ILogininfoService;
import cn.zhoutingrui.pethome.utils.AjaxResultUtil;
import cn.zhoutingrui.pethome.utils.HttpClientUtils;
import cn.zhoutingrui.pethome.utils.StrUtils;
import cn.zhoutingrui.pethome.utils.getWechatUrl;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("/login")
@Api(value = "登录",description = "登录")
public class LoginController {
    @Autowired
    private ILogininfoService logininfoService;
    @Autowired
    private RedisTemplate redisTemplate;


    @PostMapping("/shop")
    @ApiOperation("商家登录")
    public AjaxResultUtil shop(@RequestBody Logininfo logininfo){
        try {
            return logininfoService.findToLogin(logininfo);

        } catch (BussnisEptional e) {
            e.printStackTrace();
            return AjaxResultUtil.fail().setMsg(e.getMessage());
        }
    }

    @PostMapping("/wechat")
    @ApiOperation("微信扫码登录")
    public AjaxResultUtil wechat(@RequestBody WeChat weChat){
        String code = weChat.getCode();
        if (code==null){
            return AjaxResultUtil.fail().setMsg("非法访问");
        }
        return logininfoService.wechatLogin(code);


    }
}
